#!/bin/bash

# 检查是否传入用户名参数
if [ -z "$1" ]; then
    echo "用法: $0 用户名"
    exit 1
fi

USERNAME="$1"
PASSWORD="$1"

# 创建用户
useradd "$USERNAME"
if [ $? -ne 0 ]; then
    echo "用户创建失败"
    exit 2
fi

# 设置密码
echo "$USERNAME:$PASSWORD" | chpasswd

# 添加到yian组
usermod -aG yian "$USERNAME"

cp /home/yian/.bashrc /home/"$USERNAME"/
cp -r /home/yian/Desktop/hwsw_debug/ /home/"$USERNAME"/
chown "$USERNAME":"$USERNAME" /home/"$USERNAME"/.bashrc

echo "用户 $USERNAME 创建成功，已添加到 yian 组。"